﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace StreamingServer
{
    public partial class frm_Setting : Form
    {
        string ssss = "F:\\notebook\\haha\\";//路径的正确写法 
        //string ssss = "D:\\注册文件";
        string listname=null;
        public frm_Setting()
        {
            InitializeComponent();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            FileFind filefind = new FileFind();
            //filefind.FindFolder();//测试查询文件夹,测试成功
            filefind.FindFile();//测试查询文件，测试成功
            //filefind.FindFile(ssss, lvIndexList);//测试成功
        }

        /// <summary>
        /// 遍历指定文件夹下的所有文件，并显示在listview中
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenerateIndex_Click(object sender, EventArgs e)
        {
            FileFind filefind = new FileFind();
            lvIndexList.Items.Clear();
            filefind.FindFile(ssss, lvIndexList);//测试成功
        }

       /// <summary>
       /// 删除选中的文件
       /// </summary>
       /// <param name="sender"></param>
       /// <param name="e"></param>
        private void btnDellIndex_Click(object sender, EventArgs e)
        {
            FileFind ff = new FileFind();
            if(listname!=null)
            {
                ff.DellFile(listname);
                lvIndexList.Items.Clear();
                //MessageBox.Show(listname);
            }

        }

        /// <summary>
        /// 获取listview中的文件
        /// 摘自 ：http://zhidao.baidu.com/question/318956313.html
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvIndexList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvIndexList.SelectedIndices != null && lvIndexList.SelectedIndices.Count > 0)
            {
                ListView.SelectedIndexCollection c = lvIndexList.SelectedIndices;
                listname = lvIndexList.Items[c[0]].SubItems[1].Text+"\\" + lvIndexList.Items[c[0]].SubItems[0].Text;
            }
        }

        /// <summary>
        /// 刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            btnGenerateIndex_Click(null, null);
        }
    }
}
